package com.blb.network;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

/**
 * 执行读任务的线程
 */
public class ReadRunnable implements Runnable{

    private Socket socket = null;

    public ReadRunnable(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //创建输入流对象
        try(ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
            while(true){
                //循环读取对方的消息
                String message = in.readUTF();
                System.out.println(socket.getInetAddress() + "说：" + message);
            }
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }
}
